package com.zhiwei.common.constant;

/**
 * @author ZHIWEI.YANG
 * @createtime 2019/2/1 - 16:41
 * @decription 错误枚举值
 **/
public enum ErrorEnum {

    PARAM("100000", "参数异常"),
    DATA_NULL("200000", "数据为空"),
    SERVICE_LOCAL("300000", "本地服务异常"),
    SERVICE_REMOTE("400000", "远程服务异常"),
    SERVICE_REMOTE_UNREACH("400001", "远程服务无法访问"),
    SERVICE_REMOTE_PROCESS("400002", "远程服务处理出错"),
    UNKNOWN("500000", "未知异常"),
    HTTP_TOKEN("100001", "请求访问Token过期"),
    HTTP_LOGIN("100002", "用户登陆异常");

    public String code;
    public String msg;

    ErrorEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 获取错误码对应错误信息
     *
     * @param code
     * @return
     */
    public static String getErrorMsg(String code) {

        for (ErrorEnum errorEnum : ErrorEnum.values()) {
            if (errorEnum.getCode().equalsIgnoreCase(code)) {
                return errorEnum.getMsg();
            }
        }
        return UNKNOWN.getMsg();
    }

    /**
     * 获取错误码对应错误码枚举值
     *
     * @param code
     * @return
     */
    public static ErrorEnum getErrorEnum(String code) {
        for (ErrorEnum errorEnum : ErrorEnum.values()) {
            if (errorEnum.getCode().equalsIgnoreCase(code)) {
                return errorEnum;
            }
        }
        return UNKNOWN;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
